<?php
require_once("../../resources/commons.php");
require_once("../../data/User.php");
require_once("../../data/Report.php");
require_once("../../data/Item.php");

SessionManager::getInstance()->checkSession();
displayTop("Team overview","../../resources/ajaxscripts.php",null);

$l_myUserId=SessionManager::getCurrentLoggedUserId();
$l_user=User::getFromPrimaryKey($l_myUserId);
$l_results=$l_user->getFullTeam();

$l_teamSummaryTable=new TableData("TeamSummaryTable");
$l_teamSummaryTable->addHeader("firstName","First name");
$l_teamSummaryTable->addHeader("lastName","Last name");
$l_teamSummaryTable->addHeader("openAllocatedActionsCount","Open allocated actions");
$l_teamSummaryTable->setZoomArea("ajax_team_overview_details.php");
$l_teamSummaryTable->setRecords($l_results);

if(count($l_results)!=0){
	$l_teamActivities=array();
	?>
<h1>Consolidated individual reports</h1>
<script language="javascript">
	var isConsolidaterReportDisplayed=false;
	function displayConsolidatedReports(){
		if(!isConsolidaterReportDisplayed){
			Effect.SlideDown("consolidatedReportFrame",{duration: 0.5});
			document.getElementById("expandConsolidatedReportImage").src="<?=ROOT_PATH ?>/apps/resources/images/collapse.png";
			isConsolidaterReportDisplayed=true;
		}else{
			Effect.SlideUp("consolidatedReportFrame",{duration: 0.5});
			document.getElementById("expandConsolidatedReportImage").src="<?=ROOT_PATH ?>/apps/resources/images/expands.png";
			isConsolidaterReportDisplayed=false;
		}
		return false;
	}
</script>
<a href="#" onClick="return displayConsolidatedReports();"><img id="expandConsolidatedReportImage" border="0" src="<?=ROOT_PATH ?>/apps/resources/images/expands.png"/></a>
<br/>
<div id="consolidatedReportFrame" style="display:none">
<div class="decoratedDropDownTableRow">
	<?php
	$l_firstRow=true;
	foreach($l_results as $l_teamMember){
		$l_teamActivities=array_merge($l_teamActivities,$l_teamMember->getOpenActivities());
		$l_weeklyReport=$l_teamMember->getLastReport();
		if(!$l_firstRow){
			echo "<hr>";
		}else{
			$l_firstRow=false;
		}
	?>
<p><b><?=$l_teamMember->getFullName() ?></b></p>
	<?php	
		if(isset($l_weeklyReport)){
	?>
<p>
<div style="border: 1px solid; background-color: white; padding: 5px"><?=$l_weeklyReport->getNotes() ?></div>
</p>
<a href="validate_team_report.php?id=<?=base64_encode($l_weeklyReport->getId()) ?>">Validate this report</a>
	<?php
		}else{
	?>
		<div style="color: white;background-color: red;">Weekly report not yet provided</div>
	<?php
		}
	} 
	?>
</div>
</div>

<h1>Activities of your team</h1>
<?php
$l_teamActivitiesTable=new TableData("TeamActivitiesTable");
$l_teamActivitiesTable->addHeader("title","Title");
$l_teamActivitiesTable->addHeader("description","Description");
$l_teamActivitiesTable->addHeader("responsibleUserFullName","Responsible");
$l_teamActivitiesTable->setRecords($l_teamActivities);

displayTable($l_teamActivitiesTable);
?>
	
<h1>Your team pending actions</h1>
	<?php
	displayTable($l_teamSummaryTable);
}else{
	?>
	<div style="color: white;background-color: red;">No team</div>
	<?php
}

displayBottom();
?>